package com.acme.bankapp.domain.bank;

import java.io.Serializable;

import com.acme.bankapp.domain.account.Account;

@SuppressWarnings("serial")
public class Client implements Serializable {
	private String name;
	private Gender gender;
	private Account account;
	private String emailAddress;
	
	public Client(Account account, String name, Gender gender) {
		this.account = account;
		this.name = name;
		this.gender = gender;
		this.emailAddress = this.getName() + "@" + "gmail.com";
	}
	
	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}
	
	public String getName() {
		return name;
	}

	public Account getAccount() {
		return this.account;
	}
	
	public String getClientSalutation() {
		return this.gender.getGender() + this.name;
	}

	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(obj == null) return false;
		final Client other = (Client)obj;
		if(!this.name.equals(other.name)) return false;
		if(!this.gender.equals(other.gender)) return false;
		if(!this.account.equals(other.account)) return false;
		if(!this.emailAddress.equals(other.emailAddress)) return false;
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 37;
		hash = hash + 23 * this.account.hashCode();
		hash = hash + 17 * this.gender.hashCode();
		hash = hash + 13 * this.name.hashCode();
		hash = Math.abs(hash % 89);
		return hash;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Client: " + this.gender.getGender() + this.name + "\n");
		sb.append("Account type: " + this.account.getAccountType(this.account) + "\n");
		sb.append("Account value: " + this.account.maximumAmountToWithdraw());
		return sb.toString();
	}
	
	public void checkAccount() {
		System.out.println(this.getAccount().viewHistory());
	}
}
